package com.zm.exercise.day04;

import javax.swing.text.html.HTMLDocument;
import java.util.*;

/**
 * @Author:Domen
 * @Date:2024/7/15 15:43
 */

public class CollectionTest {

    public static void main(String[] args) {
        test02();
    }

    // map 的迭代用法
    public static void test01(){
        Map<Integer, String> map = new HashMap<>();
        map.put(1,"啦");
        map.put(2,"啦啦");
        map.put(3,"啦啦啦");
        map.put(4,"啦啦啦啦");
        map.put(5,"啦啦啦啦啦");

        for (Map.Entry<Integer, String> entry : map.entrySet()) {
            String value = entry.getValue();
            if (value.equals("啦啦啦")) {
                entry.setValue("我变了哦");
            }
        }

        for (Map.Entry<Integer, String> entry : map.entrySet()) {
            Integer key = entry.getKey();
            String value = entry.getValue();

            System.out.print(key + ":" + value + "; ");
        }

        System.out.println(map);
    }

    // List 的迭代用法
    public static void test02(){

        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);

        Iterator<Integer> iterator = list.iterator();
        while (iterator.hasNext()){
            int i = iterator.next();
            System.out.print(i + " ");
        }
    }


}
